/* 
	@Copyright (c) 2007 by Denis Riabtchik. All rights reserved. See license.txt and http://jgrouse.com for details@
	$Id: FileElement.java 597 2013-04-13 21:18:16Z denis.riabtchik@gmail.com $
*/

package jgrouse.jgdoc.elements;

import jgrouse.jgdoc.TokenType;
import jgrouse.jgdoc.api.IFileElement;

public class FileElement extends RefContainer implements IFileElement
{
  
	private static final long serialVersionUID = 5816566564787267132L;

	@Override
	public String toString()
	{
		if (m_children.size() == 0)
		{
			return "";
		}
		boolean isModuleFile = isModuleFile();
		addAttribute("isModuleFile", Boolean.toString(isModuleFile));
		return super.toString();
	}
	
	public boolean isModuleFile()
	{
		RefElement first = m_children.size() == 1? m_children.values().iterator().next() : null;
		boolean isModuleFile = first != null && first.getRef().getComment().getTokenType() == TokenType.PHYS_CONTAINER;
		return isModuleFile;
	}
	
	public String getPath()
	{
		return getAttribute("path");		
	}

	public void setFullName(String pFullName)
	{
		String path = "file-" + pFullName;
		super.setFullName(path);
		addAttribute("path", path);
		setLocalName(pFullName);
		/*
		int i = path.lastIndexOf('/');
		if (i >= 0)
		{
			StringBuffer b = new StringBuffer(path);
			b.setCharAt(i, '.');
			addAttribute("path", b.toString());
		}*/
		
	}

	@Override
	public String getElementType()
	{
		return "file$";
	}

	public String getRootPath()
	{
		return getRootPath("/");
	}

}
